{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--BOOK_INFORMATION-->\n",
    "<a href=\"https://www.packtpub.com/big-data-and-business-intelligence/machine-learning-opencv\" target=\"_blank\"><img align=\"left\" src=\"data/cover.jpg\" style=\"width: 76px; height: 100px; background: white; padding: 1px; border: 1px solid black; margin-right:10px;\"></a>\n",
    "*This notebook contains an excerpt from the book [Machine Learning for OpenCV](https://www.packtpub.com/big-data-and-business-intelligence/machine-learning-opencv) by Michael Beyeler.\n",
    "The code is released under the [MIT license](https://opensource.org/licenses/MIT),\n",
    "and is available on [GitHub](https://github.com/mbeyeler/opencv-machine-learning).*\n",
    "\n",
    "*Note that this excerpt contains only the raw code - the book is rich with additional explanations and illustrations.\n",
    "If you find this content useful, please consider supporting the work by\n",
    "[buying the book](https://www.packtpub.com/big-data-and-business-intelligence/machine-learning-opencv)!*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--NAVIGATION-->\n",
    "< [Visualizing Data Using Matplotlib](02.03-Visualizing-Data-Using-Matplotlib.ipynb) | [Contents](../README.md) | [Dealing with Data Using OpenCV's TrainData Container in C++](02.05-Dealing-with-Data-Using-the-OpenCV-TrainData-Container-in-C++.ipynb) >"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualizing Data from an External Dataset\n",
    "\n",
    "As a final test for this chapter, let's visualize some data from an external dataset, such as the digits dataset from scikit-learn.\n",
    "\n",
    "We will need three tools in specific:\n",
    "- scikit-learn for the actual data\n",
    "- NumPy for data munging\n",
    "- Matplotlib for visualization.\n",
    "\n",
    "So let's start by importing all of these:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn import datasets\n",
    "import matplotlib.pyplot as plt\n",
    "% matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The first step is to actually load the data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "digits = datasets.load_digits()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we remember correctly, `digits` is supposed to have two different fields: a `data` field\n",
    "containing the actual image data, and a `target` field containing the image labels. Rather\n",
    "than trust our memory, we should simply investigate the digits object. We do this by typing\n",
    "out its name, adding a period, and then hitting the `TAB` key: `digits.<TAB>`. This will\n",
    "reveal that the `digits` object also contains some other fields, such as one called images.\n",
    "The two fields, `images` and `data`, seem to simply differ by shape:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1797, 64)\n",
      "(1797, 8, 8)\n"
     ]
    }
   ],
   "source": [
    "print(digits.data.shape)\n",
    "print(digits.images.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In both cases, the first dimension corresponds to the number of images in the dataset.\n",
    "However, `data` has all the pixels lined up in one big vector, whereas `images` preserves the\n",
    "8 x 8 spatial arrangement of each image.\n",
    "\n",
    "Thus, if we wanted to plot a single image, the `images` field would be more appropriate.\n",
    "First, we grab a single image from the dataset using NumPy's array slicing:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "img = digits.images[0, :, :]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here, we are saying that we want to grab the first row in the 1,797 items-long array and all\n",
    "the corresponding $8 \\times 8=64$ pixels. We can then plot the image using `plt`'s `imshow` function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPgAAAD8CAYAAABaQGkdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAACstJRE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Hpu\nRHzU9lxnqgtH8NWS9kfEbEQck/SkpJtanmlgEfFuROzqvf2xpBlJo+1OVQ/bY5Kul7S17VnqZPtC\nSddIeliSIuLYMMctdSPwUUkHTnl/TklCOMn2MkkrJL3e7iS1eVDSPZI+a3uQmo1Lel/So70fP7ba\nPq/toQbRhcC9wMfSPLRv+3xJT0m6OyKOtj3PoGzfIOlwREy3PUsDzpJ0laSHImKFpE8lDfVjQl0I\nfE7S0lPeH5N0qKVZamX7bM3HvS0islyRdo2kG22/o/kfp9bafrzdkWozJ2kuIk6eaW3XfPBDqwuB\nvyHpctuX9h7U2Cjp2ZZnGphta/5nuZmIeKDteeoSEfdFxFhELNP89+qliLil5bFqERHvSTpge3nv\nQ9dKGuoHRRe7N1ntIuK47TskvShpRNIjEbG35bHqsEbSrZL+antP72M/i4jnW5wJ/d0paVvvYDMr\n6baW5xlI678mA9CcLpyiA2gIgQOJETiQGIEDiRE4kBiBA4kROJAYgQOJ/Qcpuo92pLZ1pQAAAABJ\nRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f6e7688b278>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(img, cmap='gray')\n",
    "plt.savefig('figures/02.04-digit0.png')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In addition, I also specified a color map with the `cmap` argument. By default, Matplotlib\n",
    "uses MATLAB's default colormap `jet`. However, in the case of grayscale images, the gray\n",
    "colormap makes more sense."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, we can plot a whole number of digit samples using `plt`'s `subplot` function. The\n",
    "`subplot` function is the same as in MATLAB, where we specify the number of rows,\n",
    "number of columns, and current subplot index (starts counting at 1). We will use `for loop`\n",
    "to iterate over the first ten images in the dataset and every image gets assigned its own\n",
    "subplot:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image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AIGFAAAAAAJAwIAAAAABIGBAAAAAAJAwIAAAAABIGBAAAAAAJ\nAwIAAACAhAEBAAAAQGLuvvM3avYTSW/e4K9+TdI7O75g/Uqd933u/vEC6xZHBrcoed7kcCtyOHqt\nzOEtMii1M4dksAD2wi2qz2GWAeGmi5mdd/fJkS1Yibaed43ael+09bxr1db7o63nXas23h9tPOea\ntfX+uB3Om6cYAQAAAEgYEAAAAAAkox4QFka8Xi3aet41aut90dbzrlVb74+2nnet2nh/tPGca9bW\n+6P68x7paxAAAAAA1I2nGAEAAABIRjIgmNnnzOyHZvaGmR0fxZo1MLNVM3vFzPpmdr50P21HDslh\nDdqYQzJYlzZmUCKHtSGHdecw+1OMzGyPpNclPSrpiqSXJX3B3V/LunAFzGxV0qS7t/E9fqtCDslh\nDdqaQzJYj7ZmUCKHNSGH9edwFFcQPiPpDXdfcfdrkl6QdHgE6wKbkUPUgByiNDKIGpDDyo1iQNgn\n6a1NX1/Z+F4buKR/NrMLZna0dDMtRw7JYQ3amkMyWI+2ZlAihzUhh5XncGwEa9gNvteWt0562N2v\nmtndks6Z2Q/c/V9LN9VS5JAc1qCtOSSD9WhrBiVyWBNyWHkOR3EF4Yqkezd9fY+kqyNYtzh3v7rx\n77clvagPLqmhDHJIDmvQyhySwaq0MoMSOawMOaw8h6MYEF6W9Ckzu9/M7pD0hKRvjmDdoszso2Z2\n1//9WdLvSvr3sl21GjkkhzVoXQ7JYHVal0GJHFaIHFaew+xPMXL398zsS5K+I2mPpK+5+6u5163A\nr0t60cykD/47/727f7tsS+1FDslhDVqaQzJYkZZmUCKHVSGH9eeQT1IGAAAAkPBJygAAAAASBgQA\nAAAACQMCAAAAgIQBAQAAAEDCgAAAAAAgYUAAAAAAkDAgAAAAAEgYEAAAAAAk/wupNMxGwy79ugAA\nAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f6e76746c50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(14, 4))\n",
    "\n",
    "for image_index in range(10):\n",
    "    # images are 0-indexed, subplots are 1-indexed\n",
    "    subplot_index = image_index + 1\n",
    "    plt.subplot(2, 5, subplot_index)\n",
    "    plt.imshow(digits.images[image_index, :, :], cmap='gray')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--NAVIGATION-->\n",
    "< [Visualizing Data Using Matplotlib](02.03-Visualizing-Data-Using-Matplotlib.ipynb) | [Contents](../README.md) | [Dealing with Data Using OpenCV's TrainData Container in C++](02.05-Dealing-with-Data-Using-the-OpenCV-TrainData-Container-in-C++.ipynb) >"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
